//
//  DKUnathorizedSigleCenterView.m
//  DanKU
//
//  Created by 吴斌 on 2023/10/24.
//

#import "DKUnathorizedSigleCenterView.h"
@interface DKUnathorizedSigleCenterView()
@property (nonatomic, strong)UILabel * dk_titleLab;
@property (nonatomic, strong)UILabel * sigleValueLab;
@property (nonatomic, strong)UILabel * sigleTimeLab;
@end
@implementation DKUnathorizedSigleCenterView
-(instancetype)init{
    if(self == [super init]){
        self.layer.cornerRadius = DK_IsWidthScale(20);
        self.clipsToBounds = YES;
        self.backgroundColor = UIColor.whiteColor;
        self.layer.shadowColor = DK_HexA(@"#000000", 0.05).CGColor;
        self.layer.shadowOffset = CGSizeMake(0,0);
        self.layer.shadowOpacity = 1;
        self.layer.shadowRadius = 13;
        [self dk_addSubView];
    }
    return self;
}
- (void)dk_addSubView{
    self.dk_titleLab = [[UILabel alloc] init];
    self.dk_titleLab.textColor = DK_Hex(@"#333333");
    self.dk_titleLab.font = DK_FONT_Regular(15);
    self.dk_titleLab.textAlignment = NSTextAlignmentCenter;
    [self addSubview:self.dk_titleLab];
    [self.dk_titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(DK_IsWidthScale(15)));
        make.top.equalTo(@(DK_IsWidthScale(20)));
        make.height.equalTo(@(DK_IsWidthScale(21)));
    }];
    self.sigleTimeLab = [[UILabel alloc] init];
    self.sigleTimeLab.textColor = DK_Hex(@"#333333");
    self.sigleTimeLab.font = DK_FONT_Regular(12);
    self.sigleTimeLab.hidden = YES;
    [self addSubview:self.sigleTimeLab];
    [self.sigleTimeLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.dk_titleLab);
        make.top.equalTo(self.dk_titleLab.mas_bottom).offset(DK_IsWidthScale(4));
        make.height.equalTo(@(DK_IsWidthScale(17)));
    }];
    self.sigleValueLab = [[UILabel alloc] init];
    self.sigleValueLab .textColor = DK_Hex(@"#333333");
    self.sigleValueLab .font = DK_FONT_Medium(17);
    self.sigleValueLab .textAlignment = NSTextAlignmentCenter;
    [self addSubview:self.sigleValueLab ];
    [self.sigleValueLab  mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(DK_IsWidthScale(15)));
        make.top.equalTo(self.dk_titleLab.mas_bottom).offset(DK_IsWidthScale(20));
        make.height.equalTo(@(DK_IsWidthScale(24)));
    }];
    UIImageView* sigleGoImgView = [[UIImageView alloc] init];
    sigleGoImgView.userInteractionEnabled = YES;
    sigleGoImgView.image = DK_GetImage(@"dk_MainNextMore");
    [self addSubview:sigleGoImgView];
    [sigleGoImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(@(-DK_IsWidthScale(15)));
        make.bottom.equalTo(@(-DK_IsWidthScale(10)));
        make.width.equalTo(@(DK_IsWidthScale(16)));
        make.height.equalTo(@(DK_IsWidthScale(16)));
    }];
    
    UIButton * sigleGoBtn = [[UIButton alloc] init];
    [sigleGoBtn addTarget:self action:@selector(sigleGo) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:sigleGoBtn];
    [sigleGoBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(@(DK_IsWidthScale(0)));
    }];
}
- (void)setIsLeft:(BOOL)isLeft{
    _isLeft = isLeft;
    if(_isLeft){
        self.dk_titleLab.text = @"Limit Available";
        self.sigleValueLab.text = @"₹ 0";
        self.sigleValueLab .textColor = DK_Hex(@"#333333");
    }else{
        self.sigleValueLab.text = @"-₹ 0";
        self.sigleValueLab .textColor = DK_Hex(@"#FF0000");
    }
}
- (void)sigleGo{
    if(self.CheckUserInfoBlock){
        self.CheckUserInfoBlock(self.value);
    }
}
-(void)setValue:(NSString *)value{
    _value = value;
    if(!_isLeft){
        if(_value.length&&([_value intValue] > 0)){
            self.dk_titleLab.text = @"Latest Due";
        }else{
            if(![[DKGlobalHelper defaultManager].loanSetpInfoMdl.step isEqualToString:@"100"]){//未认证
                self.dk_titleLab.text = @"No pending payment";
            }else{
                self.dk_titleLab.text = @"Unpaid amount";
            }
            self.sigleTimeLab.hidden = YES;
            [self.dk_titleLab mas_updateConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(@(DK_IsWidthScale(15)));
                make.top.equalTo(@(DK_IsWidthScale(20)));
            }];
            [self.sigleValueLab  mas_updateConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(@(DK_IsWidthScale(15)));
                make.top.equalTo(self.dk_titleLab.mas_bottom).offset(DK_IsWidthScale(20));
            }];
        }
        self.sigleValueLab.text = [NSString stringWithFormat:@"-₹ %@",[NSString makeShowMoney:_value]];
    }else{
        self.sigleTimeLab.hidden = YES;
        self.sigleValueLab.text = [NSString stringWithFormat:@"₹ %@",[NSString makeShowMoney:_value]];
    }
}
-(void)setDk_OrderListMdl:(DKOrderListModel *)dk_OrderListMdl{
    _dk_OrderListMdl = dk_OrderListMdl;
    if(!_isLeft){
        if(_value.length&&([_value intValue] > 0)){
            self.sigleTimeLab.hidden = NO;
            if(_dk_OrderListMdl.orderRecordList.count){
                DKOrderRecordListModel *orderRecordListMdl = _dk_OrderListMdl.orderRecordList.firstObject;
                self.sigleTimeLab.text = [NSString timeWithDayMonYear:orderRecordListMdl.repaymentDetail.repaymentTime];
            }
            [self.dk_titleLab mas_updateConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(@(DK_IsWidthScale(20)));
                make.top.equalTo(@(DK_IsWidthScale(15)));
            }];
            [self.sigleValueLab  mas_updateConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(@(DK_IsWidthScale(20)));
                make.top.equalTo(self.dk_titleLab.mas_bottom).offset(DK_IsWidthScale(28));
            }];
        }
    }
}
@end
